package com.ma.pojo;

public class queuePlus extends queue{
    private int[] arr;
    private int pushi;
    private int polli;
    private int size;
    private final  int limit;

    public queuePlus(int i) {
        this.arr = new int [i];
        this.pushi = 0;
        this.polli = 0;
        this.size = 0;
        this.limit = i;
    }

    public int nextIndex(int i){
        return i<limit-1?i+1:0;

    }
    public void push(int value){
        if(size==limit){
            throw new RuntimeException("栈满了！");

        }
        size++;
        arr[pushi]=value;
        pushi=nextIndex(pushi);
    }
    public int pop(){
        if(size==0){
            throw new RuntimeException("栈已空！");

        }
        size--;
        int ans=arr[polli];
        polli=nextIndex(polli);
        return ans;
    }

}
